home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / xtables.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-10-22  |  6.2 KB  |  225 lines

  1. #ifndef _XTABLES_H
  2. #define _XTABLES_H
  3.  
  4. #include <sys/socket.h> /* PF_* */
  5. #include <sys/types.h>
  6. #include <stdbool.h>
  7. #include <net/if.h>
  8. #include <linux/types.h>
  9. #include <linux/netfilter/x_tables.h>
  10.  
  11. #ifndef IPPROTO_SCTP
  12. #define IPPROTO_SCTP 132
  13. #endif
  14. #ifndef IPPROTO_DCCP
  15. #define IPPROTO_DCCP 33
  16. #endif
  17. #ifndef IPPROTO_UDPLITE
  18. #define IPPROTO_UDPLITE    136
  19. #endif
  20.  
  21. #define XTABLES_VERSION "1.4.2"
  22. #define XTABLES_VERSION_CODE (0x10000 * 1 + 0x100 * 4 + 2)
  23.  
  24. #define XTABLES_API_VERSION(x,y,z)    (0x10000*(x) + 0x100*(y) + z)
  25.  
  26. struct in_addr;
  27.  
  28. /* Include file for additions: new matches and targets. */
  29. struct xtables_match
  30. {
  31.     struct xtables_match *next;
  32.  
  33.     const char *name;
  34.  
  35.     /* Revision of match (0 by default). */
  36.     u_int8_t revision;
  37.  
  38.     u_int16_t family;
  39.  
  40.     const char *version;
  41.  
  42.     /* Size of match data. */
  43.     size_t size;
  44.  
  45.     /* Size of match data relevent for userspace comparison purposes */
  46.     size_t userspacesize;
  47.  
  48.     /* Function which prints out usage message. */
  49.     void (*help)(void);
  50.  
  51.     /* Initialize the match. */
  52.     void (*init)(struct xt_entry_match *m);
  53.  
  54.     /* Function which parses command options; returns true if it
  55.            ate an option */
  56.     /* entry is struct ipt_entry for example */
  57.     int (*parse)(int c, char **argv, int invert, unsigned int *flags,
  58.              const void *entry,
  59.              struct xt_entry_match **match);
  60.  
  61.     /* Final check; exit if not ok. */
  62.     void (*final_check)(unsigned int flags);
  63.  
  64.     /* Prints out the match iff non-NULL: put space at end */
  65.     /* ip is struct ipt_ip * for example */
  66.     void (*print)(const void *ip,
  67.               const struct xt_entry_match *match, int numeric);
  68.  
  69.     /* Saves the match info in parsable form to stdout. */
  70.     /* ip is struct ipt_ip * for example */
  71.     void (*save)(const void *ip, const struct xt_entry_match *match);
  72.  
  73.     /* Pointer to list of extra command-line options */
  74.     const struct option *extra_opts;
  75.  
  76.     /* Ignore these men behind the curtain: */
  77.     unsigned int option_offset;
  78.     struct xt_entry_match *m;
  79.     unsigned int mflags;
  80. #ifdef NO_SHARED_LIBS
  81.     unsigned int loaded; /* simulate loading so options are merged properly */
  82. #endif
  83. };
  84.  
  85. struct xtables_target
  86. {
  87.     struct xtables_target *next;
  88.  
  89.     const char *name;
  90.  
  91.     /* Revision of target (0 by default). */
  92.     u_int8_t revision;
  93.  
  94.     u_int16_t family;
  95.  
  96.     const char *version;
  97.  
  98.     /* Size of target data. */
  99.     size_t size;
  100.  
  101.     /* Size of target data relevent for userspace comparison purposes */
  102.     size_t userspacesize;
  103.  
  104.     /* Function which prints out usage message. */
  105.     void (*help)(void);
  106.  
  107.     /* Initialize the target. */
  108.     void (*init)(struct xt_entry_target *t);
  109.  
  110.     /* Function which parses command options; returns true if it
  111.            ate an option */
  112.     /* entry is struct ipt_entry for example */
  113.     int (*parse)(int c, char **argv, int invert, unsigned int *flags,
  114.              const void *entry,
  115.              struct xt_entry_target **targetinfo);
  116.  
  117.     /* Final check; exit if not ok. */
  118.     void (*final_check)(unsigned int flags);
  119.  
  120.     /* Prints out the target iff non-NULL: put space at end */
  121.     void (*print)(const void *ip,
  122.               const struct xt_entry_target *target, int numeric);
  123.  
  124.     /* Saves the targinfo in parsable form to stdout. */
  125.     void (*save)(const void *ip,
  126.              const struct xt_entry_target *target);
  127.  
  128.     /* Pointer to list of extra command-line options */
  129.     const struct option *extra_opts;
  130.  
  131.     /* Ignore these men behind the curtain: */
  132.     unsigned int option_offset;
  133.     struct xt_entry_target *t;
  134.     unsigned int tflags;
  135.     unsigned int used;
  136. #ifdef NO_SHARED_LIBS
  137.     unsigned int loaded; /* simulate loading so options are merged properly */
  138. #endif
  139. };
  140.  
  141. /* Your shared library should call one of these. */
  142. extern void xtables_register_match(struct xtables_match *me);
  143. extern void xtables_register_target(struct xtables_target *me);
  144.  
  145. extern int string_to_number_ll(const char *s,
  146.                    unsigned long long min,
  147.                    unsigned long long max,
  148.                    unsigned long long *ret);
  149. extern int string_to_number_l(const char *s,
  150.                   unsigned long min,
  151.                   unsigned long max,
  152.                   unsigned long *ret);
  153. extern int string_to_number(const char *s,
  154.                 unsigned int min,
  155.                 unsigned int max,
  156.                 unsigned int *ret);
  157. extern bool strtonuml(const char *, char **, unsigned long *,
  158.     unsigned long, unsigned long);
  159. extern bool strtonum(const char *, char **, unsigned int *,
  160.     unsigned int, unsigned int);
  161. extern int service_to_port(const char *name, const char *proto);
  162. extern u_int16_t parse_port(const char *port, const char *proto);
  163. extern void
  164. parse_interface(const char *arg, char *vianame, unsigned char *mask);
  165.  
  166. enum exittype {
  167.     OTHER_PROBLEM = 1,
  168.     PARAMETER_PROBLEM,
  169.     VERSION_PROBLEM,
  170.     RESOURCE_PROBLEM,
  171.     P_ONLY_ONCE,
  172.     P_NO_INVERT,
  173.     P_BAD_VALUE,
  174.     P_ONE_ACTION,
  175. };
  176.  
  177. /* this is a special 64bit data type that is 8-byte aligned */
  178. #define aligned_u64 u_int64_t __attribute__((aligned(8)))
  179.  
  180. int check_inverse(const char option[], int *invert, int *my_optind, int argc);
  181. void exit_error(enum exittype, const char *, ...)__attribute__((noreturn,
  182.                               format(printf,2,3)));
  183. extern void param_act(unsigned int, const char *, ...);
  184. extern const char *program_name, *program_version;
  185.  
  186. extern const char *ipaddr_to_numeric(const struct in_addr *);
  187. extern const char *ipaddr_to_anyname(const struct in_addr *);
  188. extern const char *ipmask_to_numeric(const struct in_addr *);
  189. extern struct in_addr *numeric_to_ipaddr(const char *);
  190. extern struct in_addr *numeric_to_ipmask(const char *);
  191. extern void ipparse_hostnetworkmask(const char *, struct in_addr **,
  192.     struct in_addr *, unsigned int *);
  193.  
  194. extern struct in6_addr *numeric_to_ip6addr(const char *);
  195. extern const char *ip6addr_to_numeric(const struct in6_addr *);
  196. extern const char *ip6addr_to_anyname(const struct in6_addr *);
  197. extern const char *ip6mask_to_numeric(const struct in6_addr *);
  198. extern void ip6parse_hostnetworkmask(const char *, struct in6_addr **,
  199.     struct in6_addr *, unsigned int *);
  200.  
  201. /**
  202.  * Print the specified value to standard output, quoting dangerous
  203.  * characters if required.
  204.  */
  205. extern void save_string(const char *value);
  206.  
  207. #ifdef NO_SHARED_LIBS
  208. #    ifdef _INIT
  209. #        undef _init
  210. #        define _init _INIT
  211. #    endif
  212.     extern void init_extensions(void);
  213. #else
  214. #    define _init __attribute__((constructor)) _INIT
  215. #endif
  216.  
  217. /* Present in both iptables.c and ip6tables.c */
  218. extern u_int16_t parse_protocol(const char *s);
  219.  
  220. #ifdef XTABLES_INTERNAL
  221. #    include <xtables/internal.h>
  222. #endif
  223.  
  224. #endif /* _XTABLES_H */
  225.